#include <iostream>
#include <queue>
template <class T>
class TreeNode{
    T key;
    TreeNode<T>* LT;
    TreeNode<T>* RT;
    TreeNode(T value){
        key = value;
        LT = NULL;
        RT = NULL;
    }
};

template <class T>
struct Treenum{
    int num;
    TreeNode<T>* node;
    Treenum(int n, TreeNode<T>* p){
        num = n;
        node = p;
    }
};
template <class T>
void levelorder(TreeNode<T>* root){
    std::queue<Treenum<T>*> Q;
    TreeNode<T>* p=root;
    if (root==NULL) return;
    Q.push(new Treenum<T>(1, root));

    while (!Q.empty()){
        Treenum *a = Q.front();
        Q.pop();
        std::cout<<a->node->key<<" "<<a->num<<endl;
        if (a->node->LT!=NULL){
            Q.push(new Treenum<T>((a->num)+1,a->node->LT));
        }
        if (a->node->RT!=NULL){
            Q.push(new Treenum<T>((a->num)+1,a->node->RT));
        }
    }
}